package de.gwtprime.server.model;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import de.gwtprime.server.sql.helper.HibernateHelper;

@Entity
@Table(name = "voteSectionComplete")
public class VoteSectionComplete extends EntityBase {

	/**
	 * SerialVersionUID
	 */
	private static final long serialVersionUID = 1L;
	
	private ArticleSection articleSection;
	private User2 user;

	@ManyToOne
	@JoinColumn
	public ArticleSection getArticleSection() {
		return articleSection;
	}

	public void setArticleSection(ArticleSection section) {
		this.articleSection = section;
	}

	public void remove(){
		long id = getArticleSection().getId();
		super.remove();
		HibernateHelper.find(ArticleSection.class, id).decreaseVoteValueAndPersist();
	}

	@ManyToOne
	@JoinColumn
	public User2 getUser() {
		return user;
	}

	public void setUser(User2 user) {
		this.user = user;
	}


	public Long getTest() {
		if(articleSection == null)
			return 0l;
		return articleSection.getId();
	}

	public void setTest(Long test) {
		this.test = test;
	}
	private Long test = 0l;

}
